$.ajaxPrefilter(function (o) {
    // 统一添加url地址
    o.url = 'http://api-breakingnews-web.itheima.net' + o.url
    // 为my接口的统一添加token 凭证
    if (o.url.indexOf('/my/' !== -1)) {
        o.headers = {
            Authorization: localStorage.getItem('token')
        }
    }
    // 检测是否有登录权限
    o.complete = function (res) {
        res = res.responseJSON
        if (res.status === 1 && res.message === '身份认证失败！') {
            layui.layer.alert(res.message, { closeBtn: 0 }, function (index) {
                localStorage.removeItem('token')
                location.replace('/login.html')
                layer.close(index)
            })
        }
    }
})